class GwtBuyerController<GwtController
  @@LOG_FLAG="GwtBuyerController"
  def index
    user_id = session[:id]
    if user_id==nil
      render :text => '请通过阿里平台登录后'
      return
    end
    start = 0
    limit = 6
    @agents = WWW::Tkd::Agent.find(:all)
    orders = WWW::Tkd::TbBuyerOrder.find_on_page(user_id,start.to_i,limit.to_i)
    @tb_orders=Array.new
    orders.each do|item|
      @tb_orders.push(WWW::Tkd::GwtBuyerOrder.init_by_order(item))
    end
    result = Hash.new
    result['offset']=start.to_i
    result['count']=WWW::Tkd::TbBuyerOrder.count user_id
    result['items']=@tb_orders
    render :text => result.to_json
  end
  #主视图
  def view
    #预先判定是否是淘宝用户
    domain_login_id=params['domain_login_id']
    if domain_login_id!=nil
            conv = Iconv.new("UTF-8","GB2312")
            domain_login_id = conv.iconv(domain_login_id)
            user_id = params['user_id']
            app_instance_id = params['app_instance_id']
            hash_code='xxxx'

            tb_user=WWW::Tkd::TbUser.save_from_aliww(domain_login_id,user_id,app_instance_id,hash_code,0)
            if tb_user==nil
               render :text =>'尊敬的用户，本次登录为非法'
            end
            session[:user_id]=tb_user.user_id
            session[:id]=tb_user.id
            session[:sip_sessionid]=tb_user.sip_sessionid
            session[:domain_login_id]=tb_user.domain_login_id

            session[:sip_sessionid]=tb_user.sip_sessionid
            session[:domain_login_id]=tb_user.domain_login_id

            app_id='17886'
            cert_code='f14a71f0b09011ddb3e6cfd602199686'
            sip_url_pre='http://sip.alisoft.com/sip/rest'
            isv_url_pre='http://buyer.taokuaidi.cn/gwt_buyer/success'
            WWW::Ali.set_app_id app_id
            WWW::Ali.set_cert_code cert_code
            WWW::Ali.set_sip_url_pre sip_url_pre
            WWW::Ali.set_isv_url_pre isv_url_pre
   end

    @isAPIExtendTime = is_valid_login
    user_id = session[:id]
    if user_id==nil
      render :text => '请通过阿里平台登录后'
      return
    end
  end

end
